/////////////////////////////////////////////////////////////////////////////
// Name:        ax_menu_text.h
// Purpose:     Text menu item class
// Author:      Julian Smart
// Modified by:
// Created:     2009-03-20
// RCS-ID:
// Copyright:   (c) Julian Smart
// Licence:     New BSD License
/////////////////////////////////////////////////////////////////////////////

#ifndef _AX_MENU_TEXT_H_
#define _AX_MENU_TEXT_H_

class AxTextMenuItem;

/*
 * Includes
 */

#include "ax/ax_menu.h"
#include "ax/ax_activator.h"
#include "ax/ax_validator.h"

/**
    @class AxTextActivator

    Used by AxTextMenuItem, as the top-level activator.

    @category{ax}
 */

class AxTextActivator: public AxAutoUpdateActivator
{
public:
    
    DECLARE_DYNAMIC_CLASS( AxTextActivator )

public:
// Constructors

    AxTextActivator() {}

    AxTextActivator(
        const wxString& labelSpec,
        const wxString& descriptionSpec);

    AxTextActivator(const AxTextActivator& activator) { Init(); Copy(activator); }

    void Init();

    void Copy(const AxTextActivator& activator);

    virtual AxActivator* Clone() const { return new AxTextActivator(* this); }

    /// Called when the user activates a menu item by pressing return or double-clicking
    virtual AxMenu* Activate(AxMenuController* controller, AxMenuItem* item);

    /// Create menu label or description
    virtual wxString CreateString(const wxString& spec, bool isLabel);

    AxTextMenuItem* GetTextMenuItem() const;

protected:
};

/**
    @class AxTextMenuItem

    This menu item shows a text input dialog when activated.
    @a label and @a description can both contain the %VALUE% keyword,
    which will be substituted with the current value.

    Set the style to @c axMENU_STYLE_MULTILINE_TEXT if you wish the input dialog
    to show a multiline text control.

    When the value is changed, a @c wxEVT_COMMAND_TEXT_UPDATED event
    is generated.

    @category{ax}
 */

#define axMENU_STYLE_MULTILINE_TEXT 0x0010

class AxTextMenuItem: public AxMenuItem
{
    DECLARE_DYNAMIC_CLASS( AxTextMenuItem )

public:
// Constructors

    AxTextMenuItem(const AxTextMenuItem& item) { Copy(item); }
    AxTextMenuItem() {}
    AxTextMenuItem(const wxString& label,
        const wxString& description,
        const wxString& id,
        const wxString& caption,
        const wxString& message,
        const wxString& value,
        int style = 0);
    bool Create(const wxString& label,
        const wxString& description,
        const wxString& id,
        const wxString& caption,
        const wxString& message,
        const wxString& value,
        int style = 0);

    void Init() {}

    void Copy(const AxTextMenuItem& item)
    {
        AxMenuItem::Copy(item);

        m_caption = item.m_caption;
        m_message = item.m_message;
        m_value = item.m_value;
    }

    AxMenuItem* Clone() const { return new AxTextMenuItem(*this); }

    /// Set caption
    void SetCaption(const wxString& caption) { m_caption = caption; }

    /// Get caption
    const wxString& GetCaption() const { return m_caption; }

    /// Set message
    void SetMessage(const wxString& msg) { m_message = msg; }

    /// Get message
    const wxString& GetMessage() const { return m_message; }

    /// Set value
    void SetValue(const wxString& value);

    /// Get value
    const wxString& GetValue() const { return m_value; }

    void SendTextUpdate(const wxString& value);

    wxString CreateString(const wxString& spec, bool isLabel);

protected:

    wxString        m_caption;
    wxString        m_message;
    wxString        m_value;
};

/**
    @class AxTextValidator
 */

class AxTextValidator: public AxValidator
{
    DECLARE_DYNAMIC_CLASS( AxTextValidator )

public:
// Constructors

    AxTextValidator(const AxTextValidator& validator) { Init(); Copy(validator); }
    AxTextValidator(wxString* ptr) { Init(); m_stringPtr = ptr; }
    AxTextValidator() { Init(); }
    ~AxTextValidator() {}

// Operations

    void Copy(const AxTextValidator& validator)
    {
        AxValidator::Copy(validator);

        m_stringPtr = validator.m_stringPtr;
    }

    virtual AxValidator* Clone() const { return new AxTextValidator(*this); }

    /// Override to pass a value from the UI to a data structure
    virtual bool TransferDataFromMenu();

    /// Override to pass a value from a data structure to the UI
    virtual bool TransferDataToMenu();

    /// Initialize variables
    void Init() { m_stringPtr = NULL; }

protected:
    wxString*   m_stringPtr;
};


#endif
    // _AX_MENU_CHOICE_H_
